package com.megvii.corelib.util;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

/**
 * Created by linyue on 15/12/23.
 */
public class MegviiToast
{
    private static Toast lastToast;
    /**
     * 输出toast
     */
    public static void showToast(Context context, String str)
    {
        showToast(context, str, Toast.LENGTH_SHORT);
    }

    /**
     * 输出长时间toast
     */
    public static void showLongToast(Context context, String str)
    {
        showToast(context, str, Toast.LENGTH_LONG);
    }

    private static void showToast(Context context, String str, int toastLength)
    {
        if (context != null)
        {
            if (lastToast != null)
            {
                lastToast.cancel();
            }
            Toast toast = Toast.makeText(context, str, toastLength);
            // 可以控制toast显示的位置
            toast.setGravity(Gravity.TOP, 0, 30);
            toast.show();
            lastToast = toast;
        }
    }
}
